/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mnstudent.dataacesslayer;

import mnstudent.datatranferobject.KindOfSubjectDTO;
import java.sql.ResultSet;

/**
 *
 * @author 11520_000
 */
public class KindOfSubjectDAL {
     
    //<editor-fold defaultstate="collapsed" desc="Attributes">
    private KindOfSubjectDTO m_KindOfSubjectObj;
    private DataExecuteUseStoreProcedure m_DataExecute;
    private String  m_sqlCmd;
    
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="Method">
    public KindOfSubjectDAL() {
        this.m_KindOfSubjectObj = new KindOfSubjectDTO();
        this.m_DataExecute = new DataExecuteUseStoreProcedure();    
        this.m_sqlCmd = "";
    }

    /**
     * Ham lay tat ca cac LoaiMonHoc
     *
     * @return boolean
     */
    public ResultSet getAllKindOfSubject() {
       try
        {
            m_sqlCmd = "{Call GetAllKindOfSubjectFromDatabase}";
            ResultSet _rsData = this.m_DataExecute.getDataFromDatabase(m_sqlCmd,null);
            return _rsData;
        }catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }
    /**
     * Ham lay LoaiMonHoc theo ma LoaiMonHoc
     * @param _id
     * @return tra ve table chon
     */
    public ResultSet getKindOfSubjectById(String _id)
    {
        try {
            m_sqlCmd = "{Call GetKindOfSubjectByIdFromDatabase(?)}";
            String[] arrId = {_id};
            return this.m_DataExecute.getDataFromDatabase(m_sqlCmd, arrId);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }
    
     /**
     * ham them moi LOAIMONHOC xuong database
     * @param _kindofsubject
     * @return true: success, false: fail
     */
    public boolean insertKindOfSubjectToDatabase(KindOfSubjectDTO _kindofsubject)
    {
       try {
           m_sqlCmd = "{Call InsertKindOfSubjectToDatabase(?,?,?,?)}";
           String[] arrStr = {_kindofsubject.getKindOfSubjectID(), _kindofsubject.getNameOfKind(), String.valueOf(_kindofsubject.getAmountOfMoneyPerCredit()), String.valueOf(_kindofsubject.getCountLessonsConversion())};

           return this.m_DataExecute.updateDataToDatabase(m_sqlCmd,arrStr)>0;
           
       } catch (Exception ex) {
          ex.printStackTrace();
       }
        return false;
    }
    
    /**
     * Ham cap nhat sua doi thong tin LOAIMONHOC
     * @param _kindofsubject
     * @return tue: thanh cong, false: that bai
     */
    public boolean updateKindOfSubjectToDatabase(KindOfSubjectDTO _kindofsubject)
    {
       try {
           m_sqlCmd = "{Call UpdateKindOfSubjectToDatabase(?,?,?,?)}";
           String[] arrStr = {_kindofsubject.getKindOfSubjectID(),  _kindofsubject.getNameOfKind(), String.valueOf(_kindofsubject.getAmountOfMoneyPerCredit()), String.valueOf(_kindofsubject.getCountLessonsConversion())};

           return this.m_DataExecute.updateDataToDatabase(m_sqlCmd,arrStr)>0;
           
       } catch (Exception ex) {
          ex.printStackTrace();
       }
        return false;
    }
    
    /**
     * Ham xoa mot LOAIMONHOC ra khoi database
     * @param _kindofsubject
     * @return 
     */
     public boolean deleteKindOfSubjectFromDatabase(KindOfSubjectDTO _kindofsubject)
    {
        try {
           m_sqlCmd = "{Call DeleteKindOfSubjectFromDatabase(?)}";
           String[] arrStr = {_kindofsubject.getKindOfSubjectID()};

           return this.m_DataExecute.updateDataToDatabase(m_sqlCmd,arrStr)>0;
           
       } catch (Exception ex) {
          ex.printStackTrace();
       }
        return false;
    }
    //</editor-fold>
}
